package com.jetinno.file

import android.app.Dialog
import android.view.View
import android.widget.EditText
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * Created by zhangyuncai on 2023/9/21.
 */
class CommonCharAdapter(
    private val dialog: Dialog,
    private val mDatas: List<String>,
    private val editText: EditText
) : BaseQuickAdapter<String,BaseViewHolder>(
    R.layout.item_commonchar_adapter,mDatas
) {
    override fun convert(helper: BaseViewHolder, item: String) {
        val tv_commonchar_content =helper.getView<TextView>(R.id.tv_commonchar_content)
        tv_commonchar_content.text = item
        tv_commonchar_content.setOnClickListener { v: View? ->
            val selectionStart = editText.selectionStart
            val selectionEnd = editText.selectionEnd
            val editable = editText.text
            editable.delete(selectionStart, selectionEnd)
            editable.insert(selectionStart, item)
            dialog.dismiss()
        }
    }


}
